package com.service.user;

import com.common.PageResultUtil;
import com.entity.Manager;
import com.entity.User;
import com.facade.user.r.IManagerFacadeR;
import com.facade.user.r.IUserFacadeR;
import com.mapper.CustomMapper;
import com.mapper.ManagerMapper;
import com.mapper.UserMapper;
import com.query.IQueryComplex;
import com.query.ManagerQueryLink;
import com.service.CustomServiceR;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ManagerServiceR extends CustomServiceR<Manager> implements IManagerFacadeR {

    @Resource
    private ManagerMapper mapper;

    @Override
    protected CustomMapper<Manager> initMapper() {
        return mapper;
    }

    @Override
    public PageResultUtil<Manager> queryManagerPageLink(IQueryComplex query) {
        PageResultUtil<Manager> pageResultUtil = new PageResultUtil<>();
        Map<String, Object> params = query.params();
        int count = mapper.queryManagerCountLink(params);
        createPageParamForQueryLink(params, count, query.getStart(), query.getLength(), pageResultUtil);
        if (count > 0) {
            List<Manager> retList = mapper.queryManagerPageLink(params);
            pageResultUtil.setItems(retList);
        }
        return pageResultUtil;
    }

    @Override
    public PageResultUtil<Manager> queryManagerList(IQueryComplex query) {
        PageResultUtil<Manager> pageResultUtil = new PageResultUtil<>();
        Map<String, Object> params = query.params();
        int count = mapper.queryManagerCount(params);
        createPageParamForQueryLink(params, count, query.getStart(), query.getLength(), pageResultUtil);
        if (count > 0) {
            List<Manager> retList = mapper.queryManagerList(params);
            pageResultUtil.setItems(retList);
        }
        return pageResultUtil;
    }

    @Override
    public List<Manager> queryManagerListByDepartmentId(Long departmentId) {
        ManagerQueryLink query = new ManagerQueryLink();
        query.setLength(Integer.MAX_VALUE);
        if (null != departmentId) {
            query.setDepartmentId(departmentId);
        }
        PageResultUtil<Manager> result = this.queryManagerList(query);
        return result.getItems();
    }
}
